﻿using MediatR;
using SystemMHB.API.Application.Command.WarehouseCommand;
using SystemMHB.Infrstructer.Interface;

namespace SystemMHB.API.Application.CommandHandlers.WarehouseCommandHandler
{
    public class WarehouseDeleteCommandHandler:IRequestHandler<WarehouseDeleteCommand,int>
    {
        /// <summary>
        /// 仓库管理仓储
        /// </summary>
        IWarehouseRepository WarRep;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="WarRep">仓库管理仓储</param>
        public WarehouseDeleteCommandHandler(IWarehouseRepository WarRep)
        {
            this.WarRep = WarRep;
        }


        public async Task<int> Handle(WarehouseDeleteCommand request, CancellationToken cancellationToken)
        {
            request.DelectName = "张三";
            request.DelectTime = DateTime.Now.ToUniversalTime();
            var qouer = await WarRep.GetModelAsync(request.warehouseID);
            qouer.IsDel = true;
            qouer.DelectName = request.DelectName;
            qouer.DelectTime = request.DelectTime;
            return await WarRep.UpdateAsync(qouer);
        }
    }
}
